package com.dance.sharevalidator.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResultVo<T> {

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 状态码
     */
    private String code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    public ResultVo() {
    }

    public ResultVo(Boolean success) {
        this.success = success;
    }

    public ResultVo(Boolean success, String code) {
        this(success);
        this.code = code;
    }

    public ResultVo(Boolean success, String code, String msg) {
        this(success, code);
        this.msg = msg;
    }

    public ResultVo(Boolean success, String code, String msg, T data) {
        this(success,code,msg);
        this.data = data;
    }

    public static ResultVo<Object> success() {
        return new ResultVo<>(true);
    }

    public static <T> ResultVo<T> success(T data) {
        return new ResultVo<>(true, "","", data);
    }

    public static ResultVo<Object> error() {
        return new ResultVo<>(false, "500");
    }

    public static ResultVo<Object> error(String msg) {
        return new ResultVo<>(false, "500", msg);
    }

    public static <T> ResultVo<Object> error(String msg, T data) {
        return new ResultVo<>(false, "500", msg, data);
    }

}
